package com.wc.alorithm_blue_bridge._BFS.迷宫;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/3/12 7:59
 * @description
 * https://www.lanqiao.cn/courses/46292/learning/?id=3922912&compatibility=false
 */
public class Main {
    /**
     * 思路：
     * 从n * n开始扩展, 扩展到所有格子
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 2010;
    static int[] h = new int[N * N << 1], e = new int[N * N << 1], ne = new int[N * N << 1];
    static int[][] dist = new int[N][N];
    static int[] q = new int[N * N << 1], dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
    static int n, m, idx = 1;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        while (m-- > 0) {
            int x1 = sc.nextInt(), y1 = sc.nextInt();
            int x2 = sc.nextInt(), y2 = sc.nextInt();
            int a = x1 * N + y1, b = x2 * N + y2;
            // 保存传送
            add(a, b);
            add(b, a);
        }
        bfs();
        int sum = 0;
        dist[n][n] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                sum += dist[i][j];
            }
        }
        out.printf("%.2f\n", 1.0 * sum / (n * n));
        out.flush();
    }

    static void bfs() {
        int hh = 1, tt = 1;
        q[tt++] = n;
        q[tt++] = n;
        while (hh < tt) {
            int x = q[hh++], y = q[hh++];
            // 先上下左右
            for (int i = 0; i < 4; i++) {
                int a = x + dx[i], b = y + dy[i];
                if (a < 1 || b < 1 || a > n || b > n) continue;
                if (dist[a][b] > 0) continue;
                dist[a][b] = dist[x][y] + 1;
                q[tt++] = a;
                q[tt++] = b;
            }
            // 传送
            int t = x * N + y;
            for (int i = h[t]; i > 0; i = ne[i]) {
                int j = e[i], a = j / N, b = j % N;
                if (dist[a][b] > 0) continue;
                dist[a][b] = dist[x][y] + 1;
                q[tt++] = a;
                q[tt++] = b;
            }
        }
    }

    static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

